
function mathch(chart: string): number{
    let x: number = 0;
    if(chart === 'I') x = 1;
    if(chart === 'V') x =5;
    if(chart === 'X') x =10;
    if(chart === 'L') x =50;
    if(chart === 'C') x =100;
    if(chart === 'D') x =500;
    if(chart === 'M') x =1000;
    return x;
}

function romanToInt(s: string): number {
    let sum: number = 0;
    for( let i = 0;i< s.length;i++ ){
        
        if(s[i] === 'I' && (s[i+1] === 'V' || s[i+1] === 'X') ){       
            sum-=2;
        }
        if(s[i] === 'X' && (s[i+1] === 'L' || s[i+1] === 'C') ){    
            sum-=20;
        }
        if(s[i] === 'C' && (s[i+1] === 'D' || s[i+1] === 'M') ){    
            sum-=200;
        }
        sum += mathch(s[i]);
    }
    return sum;
};

let str = "MCMXCIV"
let sum = romanToInt(str);
console.log(sum);